﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Linq.Expressions;

namespace AirLinq {
	public class AirLinqQueryable<T> : IQueryable<T>{
		private readonly Expression _expression;
		private readonly AirLinqProvider _provider;
		public AirLinqQueryable(Expression expression, AirLinqProvider provider) {
			_expression = expression;
			_provider = provider;
		}
		#region IEnumerable<T> Members
		public IEnumerator<T> GetEnumerator() {
			return _provider.Execute<IEnumerator<T>>(_expression);
		}
		#endregion
		#region IEnumerable Members
		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}
		#endregion
		#region IQueryable Members
		Type IQueryable.ElementType {
			get {
				return typeof(T);
			}
		}
		Expression IQueryable.Expression {
			get {
				return _expression;
			}
		}
		IQueryProvider IQueryable.Provider {
			get {
				return _provider;
			}
		}
		#endregion
		public override string ToString() {
			return _provider.GenerateQueryString(_expression);
		}
	}
}
